package com.yzg.timing;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @author misterWei
 * @create 2020年06月14号:18点20分
 * @mailbox forcontinue@163.com
 */
@Slf4j(topic = "c.TimerMain")
public class TimerMain {

    public static void main(String[] args) {
        /**
         * 缺点一,调度执行串行执行,效率不高
         * 缺点二,执行报错后,其它任务不在执行,稳定性不高.
         */
        Timer timer = new Timer();
        TimerTask task1 = new TimerTask() {
            @SneakyThrows
            @Override
            public void run() {
               log.info("任务调度{}",1);
               int i = 1/0;
               Thread.sleep(2000L);
            }
        };

        TimerTask task2 = new TimerTask() {
            @Override
            public void run() {
                log.info("任务调度{}",2);
            }
        };
        timer.schedule(task1,1000L);
        timer.schedule(task2,1000L);
         }
    }
